package com.starlink.controller.wechat;

import com.github.pagehelper.PageInfo;
import com.starlink.common.WebResponse;
import com.starlink.common.annotation.WebAccess;
import com.starlink.model.request.SchoolbagGroupBagRequest;
import com.starlink.model.vo.SchoolbagGroupBagVO;
import com.starlink.service.SchoolbagGroupBagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.SortDefault;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @author zhanghong
 */
@RestController
@RequestMapping("/wechat/schoolbag/groupBag")
@Api(value = "【小程序端】分组书包模块", tags = {"【小程序端】分组书包模块"})
public class WechatSchoolbagGroupBagController {

    @Autowired
    private SchoolbagGroupBagService schoolbagGroupBagService;

    @WebAccess(login = true)
    @ApiOperation(value = "根据主键查询", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/get/{id}")
    public WebResponse<SchoolbagGroupBagVO> getByKey(HttpServletRequest request, @PathVariable("id") long id) {
        return WebResponse.build(schoolbagGroupBagService.getByKey(id));
    }

    @WebAccess(login = true)
    @ApiOperation("分页查询")
    @PostMapping("/pageQuery")
    public WebResponse<PageInfo<SchoolbagGroupBagVO>> pageQuery(@SortDefault(sort = {"create_time"}, direction = Sort.Direction.DESC) Pageable pageable,
                                                           @RequestBody SchoolbagGroupBagRequest request) {
        return WebResponse.build(schoolbagGroupBagService.pageQuery(pageable,request));
    }

    @WebAccess(login = true)
    @ApiOperation("列表查询")
    @PostMapping("/listQuery")
    public WebResponse<List<SchoolbagGroupBagVO>> listQuery(@RequestBody SchoolbagGroupBagRequest request) {
        return WebResponse.build(schoolbagGroupBagService.listQuery(request));
    }

    @WebAccess(login = true)
    @ApiOperation("新增")
    @PostMapping("/add")
    public WebResponse<Boolean> add(@Valid @RequestBody SchoolbagGroupBagRequest request) {
        return WebResponse.build(schoolbagGroupBagService.add(request));
    }

    @WebAccess(login = true)
    @ApiOperation("修改")
    @PostMapping("/update")
    public WebResponse<Boolean> updateByKey(@Valid @RequestBody SchoolbagGroupBagRequest request) {
        return WebResponse.build(schoolbagGroupBagService.updateByKey(request));
    }

    @WebAccess(login = true)
    @ApiOperation("删除")
    @PostMapping("/delete")
    public WebResponse<Boolean> deleteByKey(@RequestParam("ids") String ids) {
        return WebResponse.build(schoolbagGroupBagService.deleteDOByIds(ids));
    }
}
